package org.example
import org.apache.spark.sql.SparkSession
import scala.math.random

object sparkData3_movies {
  def main(args: Array[String]): Unit = {
    val spark =SparkSession
      .builder()
      .master("local[*]")
      .getOrCreate()
    val slice=if(args.length>0) args(0).toInt else 2
    val n =math.min(100000L*slice,Int.MaxValue).toInt
    val count =spark.sparkContext.parallelize(1 until n,slice).map{i=>
      val x =random*2 -1
      val y=random *2 -1
      if (x*x+y*y <=1) 1 else 0

    }.reduce(_+_)
    println(s"Pi is roughly ${4.0 *count /(n-1)}")
    spark.stop()
  }

}
